home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
ovrsgr.zip
/
OVRSGR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-06
|
21KB
|
1,018 lines
/*********************************************************************
Name: ovrsgr.c
Version: 1.0
COPYRIGHT (c) 1985 BY DIGITAL EQUIPMENT CORPORATION, MAYNARD MASS.
ALL RIGHTS RESERVED.
Permission to copy without fee all or part of this material is granted
provided that copies are not made or distributed for direct commercial
advantage, the Digital Equipment Corporation copyright notice appears,
the disclaimer below appears, and notice is given that copying is by
permission of Digital Equipment Corporation. To copy otherwise
requires a specific license.
DISCLAIMER:
The information herein is subject to change without notice and should
not be construed as a commitment by Digital Equipment Corporation.
Digital Equipment Corporation assumes no responsibility for the use or
reliability of this software. This software is provided "as is,"
without any warranty of any kind, express or implied. Digital
Equipment Corporation will not be liable in any event for any damages
including any loss of data, profit, or savings, claims against the
user by any other party, or any other incidental or consequential
damages arising out of the use of, or inability to use, this software,
even if Digital Equipment Corporation is advised of the possibility of
such damage.
DEFECT REPORTING AND SUGGESTIONS:
Please send reports of defects or suggestions for improvement directly
to the author:
Brian Hetrick
Digital Equipment Corporation
110 Spit Brook Road ZKO1-2/J10
Nashua NH 03062-2698
Do NOT file a Software Performance Report on this software, call the
Telephone Support Center regarding this software, contact your Digital
Field Office regarding this software, or use any other mechanism
provided for Digital's supported and warranted software.
FACILITY:
General utility programs.
ABSTRACT:
Converts a file encoded in eight-bit ASCII with limited control
character use into an equivalent file using the "set graphic
rendition" escape sequences to indicate bolding and underlining.
Applicable ANSI standards are X3.4 (7-bit ASCII), X3.64 (Addition-
al controls for use with ASCII), and (proposed) X3.4.2 (8-bit
ASCII).
ENVIRONMENT:
CP/M-86/80, compiled with Mark Williams Co. MWC86.
MS-DOS, compiled with Computer Innovations Co. C86.
VAX/VMS, compiled with VAX C.
AUTHOR: Brian Hetrick, CREATION DATE: 10 May 1985.
MODIFIED BY:
Brian Hetrick, 10-May-85: Version 1.0
000 - Original creation of module.
1986/11/06 -- Rahul Dhesi -- For ANSI.SYS on Iclones: (a) changed
blob to be rectangular graphics character; (b) changed underlining
to be inverse video. See "#ifdef ICLONE".
*********************************************************************/
/*
* INCLUDE FILES:
*/
#include <stdio.h>
/*
* TABLE OF CONTENTS:
*/
/*
* MACROS:
*/
#define MAXLINLEN 512 /* Maximum width of line */
#define FLG_SPAN 1 /* Span whitespace */
#define ATR_BLOB 1 /* Different char overprint*/
#define ATR_UNDR 2 /* Underline overprint */
#define ATR_BOLD 4 /* Same char overprint */
/*
* The following character is device dependent. It should print as
* a blob of some type. It is used to indicate that several dissim-
* ilar characters have been overprinted. The sequence given invokes
* the G1 character set, prints a lowercase 'a', and returns to the
* G0 character set. On devices such as Digital's VT1xx and VT2xx
* terminals, where the G1 set has been set to the "special graphics"
* character set, this prints a checkerboard pattern. The SCS (set
* character set) escape sequence to put the special graphics char-
* acter set into G1 is <ESC>)0.
*/
#ifdef ICLONE
#define CHR_BLOB "\xFE" /* small rectangle */
#else
#define CHR_BLOB "\016a\017" /* Checkerboard */
#endif
/*
* OWN STORAGE:
*/
struct chr_pos
{
char cp_attr;
char cp_char;
};
static FILE
* outfile;
static int
flags,
hpos = 0,
indent;
static struct chr_pos
line_image [MAXLINLEN];
/*
* EXTERNAL REFERENCES:
*/
static change_attr (old_attr, new_attr)
int
old_attr,
new_attr;
/*********************************************************************
FUNCTIONAL DESCRIPTION:
Minimally updates "set graphic rendition" attributes.
The term "minimal" is used advisedly. The VT100 series and clones
allow only clearing all attributes and setting particular attri-
butes, while the VT200 series additionally allows clearing partic-
ular attributes. Also, the VT100 series and clones allow only the
7-bit ASCII representation of CSI. For maximal device independ-
ence, the VT100 limitations are assumed.
FORMAL PARAMETERS:
Old_attribute.rg.v - The set of graphic rendition attributes cur-
rently in effect.
New_attributes.rg.v - The set of graphic rendition attributes to
be put into effect.
RETURN VALUE:
None.
IMPLICIT INPUTS:
outfile - The file to which the escape sequence is to be sent.
IMPLICIT OUTPUTS:
None.
SIDE EFFECTS:
Sends an escape sequence to the output file.
*********************************************************************/
{
int
first_code;
if (old_attr != new_attr)
{
/*
* Have to do something. Start the escape sequence.
*/
putc ('\033', outfile);
putc ('[', outfile);
/*
* See if must reset attributes.
*/
if (old_attr & (~ new_attr))
{
putc ('0', outfile);
first_code = 0;
old_attr = 0;
}
else
{
first_code = 1;
}
/*
* Need only attributes to be added.
*/
new_attr &= ~ old_attr;
/*
* Do the attributes.
*/
if (new_attr & ATR_BOLD)
{
if (! first_code)
{
putc (';', outfile);
}
putc ('1', outfile);
first_code = 0;
}
if (new_attr & ATR_UNDR)
{
if (! first_code)
{
putc (';', outfile);
}
#ifdef ICLONE
putc ('7', outfile);
#else
putc ('4', outfile);
#endif
}
/*
* End the escape sequence.
*/
putc ('m', outfile);
}
}
static outlin (eol)
char
eol;
/*********************************************************************
FUNCTIONAL DESCRIPTION:
Creates a text line corresponding to the line_image array.
FORMAL PARAMETERS:
eol.rc.v - The vertical movement character that ended the line.
RETURN VALUE:
None.
IMPLICIT INPUTS:
line_image - A description of the line to be created.
outfile - The pointer to the stream upon which the line is to be
created.
IMPLICIT OUTPUTS:
None.
SIDE EFFECTS:
Produces output upon outfile.
*********************************************************************/
{
int
column,
last_attr,
span_attr;
struct chr_pos
* end_ptr,
* max_ptr,
* start_ptr;
/*
* Turn NULs into spaces and find line length.
*/
for (start_ptr = & line_image [0], max_ptr = & line_image [-1];
start_ptr < & line_image [MAXLINLEN];
start_ptr ++)
{
if (0 == start_ptr -> cp_char)
{
start_ptr -> cp_char = ' ';
if (0 != start_ptr -> cp_attr)
{
max_ptr = start_ptr;
}
}
else
{
/*
* It is not a space.
*/
max_ptr = start_ptr;
}
}
last_attr = 0;
if (max_ptr != & line_image [-1])
{
/*
* If necessary, make attributes span blanks. Do this by
* finding characters surrounding spans of blanks, and ORing
* the blank's attributes with the AND of the attributes of
* the surrounding characters.
*
* In the following, start_pos is the index of the first
* blank to treat, and start_ptr points at its line_image[]
* entry; end_pos is the index of the first character not to
* treat, and end_ptr points at its line_image[] entry. Note
* that any init